<?php
if( IN_MANAGER_MODE != "true" ){
	die( '<strong>INCLUDE_ORDERING_ERROR</b><br /><br />Please use the MODx Content Manager instead of accessing this file directly.' );
}
/* !
** AutoComplite
*/
$name = preg_replace( '/[^\.\/a-z]/i', '', isset( $_REQUEST[ 'name' ] ) ? $_REQUEST[ 'name' ] : '' );
if( $name != '' ){
	$jSam -> service[ 'printCode' ] = 0;
	$limit = (int)preg_replace( '/[^0-9]/i', '', isset( $_REQUEST[ 'limit' ] ) ? $_REQUEST[ 'limit' ] : 50 );
	$limit = is_numeric( $limit ) ? $limit : 50;
	$defaultVars = array( 'introtext', 'ta', 'pagetitle', 'longtitle', 'type', 'description', 'alias', 'link_attributes', 'isfolder', 'richtext', 'published', 'parent', 'template', 'menuindex', 'searchable', 'cacheable', 'createdby', 'createdon', 'editedby', 'editedon', 'publishedby', 'publishedon', 'pub_date', 'unpub_date', 'contentType', 'content_dispo', 'donthit', 'menutitle', 'hidemenu' );
	$isTV = !in_array( $name, $defaultVars );
	if( !$isTV ){
		$sql = $modx -> db -> query( "SELECT `$name` FROM `" . $modx -> db -> config[ 'table_prefix' ] . "site_content` LIMIT $limit" );
		$sql = $modx -> db -> makeArray( $sql );
		$array = array();
		foreach( $sql as $p ){
			if( $p[ $name ] != '' && !in_array( $p[ $name ], $array ) ){
				$array[] = $p[ $name ];
			}
		}
		echo json_encode( $array );
	}
	else{
		$sql = $modx -> db -> query( "SELECT `id` FROM `" . $modx -> db -> config[ 'table_prefix' ] . "site_tmplvars` WHERE `name`='" . $modx -> db -> escape( $name ) . "' LIMIT 1" );
		$sql = mysql_fetch_row( $sql );
		if( count( $sql ) == 0 ){
			echo '[]';
		}
		else{
			$sql = $modx -> db -> query( "SELECT `value` FROM `" . $modx -> db -> config[ 'table_prefix' ] . "site_tmplvar_contentvalues` WHERE   	
tmplvarid={$sql[0]} LIMIT $limit" );
			$sql = $modx -> db -> makeArray( $sql );
			$array = array();
			foreach( $sql as $p ){
				if( $p[ 'value' ] != '' && !in_array( $p[ 'value' ], $array ) ){
					$array[] = $p[ 'value' ];
				}
			}
			echo json_encode( $array );
		}
	}
}
?>